package com.imddy.spbatch001.joblistener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;

/**
 * @author imddy
 * Description: 监听Job执行情况，实现JobExecutorListener，且在batch配置类里，Job的Bean上绑定该监听器
 */
public class MyJobListener implements JobExecutionListener {
    private static final Logger log = LoggerFactory.getLogger(MyJobListener.class);


    @Override
    public void beforeJob(JobExecution jobExecution) {
        log.info("Job开始执行...");
        log.info("job 开始, id={}",jobExecution.getJobId());
        log.info("Job参数：{}", jobExecution.getJobParameters());
    }


    @Override
    public void afterJob(JobExecution jobExecution) {
        log.info("Job执行完毕...");
        log.info("job 开始, id={}",jobExecution.getJobId());
        log.info("Job结果：{}", jobExecution.getExitStatus());
    }

}
